<template>
  <div id="app">
    <transition :name="transitionName">
      <router-view class="Router" v-if="isRouterAlive" v-wechat-title="$route.meta.title"></router-view>
    </transition>
    <wx v-if="wxbtn"/>
  </div>
</template>

<script>
import wx from './pages/wx'
export default {
  name: 'App',
  components: { wx },
  provide () {
    return {
      reload: this.reload
    }
  },
  data() {
    return {
      wxbtn: false,
      transitionName: '',
      isRouterAlive: true
    }
  },
  created () {
    var userAgent = navigator.userAgent
    if (userAgent.includes('iPhone') || userAgent.includes('iPad')) {
      localStorage.setItem('originUrl', location.href)// 用于ios分享
    }
    this.wxbtn = true
  },
  watch: {
    $route() {
      if (this.$router.isleft) {
        this.transitionName = 'slideleft'
      }
      if (this.$router.isright) {
        this.transitionName = 'slideright'
      }
    }
  },
  methods: {
    reload () {
      this.isRouterAlive = false
      this.$nextTick(function() {
        this.isRouterAlive = true
      })
    }
  }
}
</script>

<style lang="less">
@import "~styles/variable.less";
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color:rgba(0,0,0,0);
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}
.Router {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 100%;
  background-color: @body-bg-color;;
  transition: all .5s ease;
  -webkit-transition: all .5s ease;
  -moz-transition: all .5s ease;
}
.slideleft-enter,
 .slideright-leave-active {
  opacity: 1;
  transform: translate3d(90% 0, 0);
  -webkit-transform: translate3d(90%, 0, 0);
  -moz-transform: translate3d(90%, 0, 0);
}
.slideleft-leave-active,
.slideright-enter {
 opacity: 1;
 transform: translate3d(-90% 0, 0);
 -webkit-transform: translate3d(-90%, 0, 0);
 -moz-transform: translate3d(-90%, 0, 0);
}
</style>
